package com.mhy.netsafe.utils.manager;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

/**
 * author    : mahongyin
 * e-mail    : mhy.work@qq.com
 * date      : 2019/7/11 09:50
 * introduce :
 */

public class ActivityManager {

    private static final String TAG = "ActivityManager";
    private static List<Activity> activityList = new ArrayList<Activity>();

    public static void addActivity(Activity activity) {
        if (!activityList.contains(activity)) {
            activityList.add(activity);
        }
    }

    public static void removeActivity(Activity activity) {
        if (activityList.contains(activity)) {
            activityList.remove(activity);
        }
    }

    /**
     * 退出app
     */
    public static void finishAllActivity() {
        for (Activity activity : activityList) {
            activity.finish();
        }
        activityList.clear();
    }

    /**
     * 销毁指定的activity
     * @param activity
     */
    public static void finishActivity(Activity activity) {
        if (activityList.contains(activity)) {
            activityList.remove(activity);
            activity.finish();
        }
    }
}
